package guoanmaker.operator.business.controller;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import guoanmaker.operator.business.model.InRoundPhone;
import guoanmaker.operator.business.model.OperatorHotBusiness;
import guoanmaker.operator.business.model.OperatorOfficeSpace;
import guoanmaker.operator.business.service.OperatorOfficeSpaceInterface;
import guoanmaker.operator.helper.common.AjaxJson;
import guoanmaker.operator.helper.common.abstractobj.ApiController;
import io.swagger.annotations.ApiOperation;
/**
 * 办公空间服务
* @ClassName: OperatorOfficeSpaceController
* @Description:TODO (这里用一句话描述这个类的作用) 
* @author lihongyu
* @date 2017年9月5日 上午11:17:30 
*  
 */
@RestController
@RequestMapping(ApiController.OPERATOR_OFFICE_SPACE)
public class OperatorOfficeSpaceController {
	
	@Autowired
	 private  AjaxJson ajaxJson;
	@Autowired
	private OperatorOfficeSpaceInterface operatorOfficeSpaceInterface;
	 @ApiOperation(value = "保存办公空间服务", notes = "新增/修改办公空间服务")
	    @PostMapping(value = "saveOperatorOperatorOfficeSpace")
	    public AjaxJson saveHeadline(@RequestBody InRoundPhone inRoundPhone) {
	    	try{
	    		OperatorOfficeSpace[] appheads=inRoundPhone.getOperatorOfficeSpace();
	    		operatorOfficeSpaceInterface.delectAllBycitycode(inRoundPhone.getCityId());
		    	for(OperatorOfficeSpace apphead:appheads){
		    		/*if(apphead.getId()!=null&&!apphead.getId().equals("")){
		    			operatorOfficeSpaceInterface.deleteOperatorOfficeSpace(apphead.getId());}*/
		    		apphead.setCreateDate(new Date());
		    		
		    		apphead.setCityId(inRoundPhone.getCityId());
		    		operatorOfficeSpaceInterface.saveOperatorOfficeSpace(apphead);
		    	}
		    	ajaxJson.setSuccess(true).setStatus(200).setData(null);
	    	}catch(Exception e){
	    		ajaxJson.setSuccess(true).setStatus(250).setData(null);
	    	}
	        return ajaxJson;
	    }

	 
	 @ApiOperation(value = "查询所有办公空间", notes = "查询所有所有办公空间")
	    @PostMapping(value = "getAllOperatorOperatorOfficeSpace")
	    public AjaxJson getAllOperatorOperatorOfficeSpace(String cityId) {
	    	try{
	    	List<OperatorOfficeSpace> ops=operatorOfficeSpaceInterface.getAllOperatorOfficeSpace(cityId);
	    	
	        	ajaxJson.setSuccess(true).setStatus(200).setData(ops);
	        
	    	}catch(Exception e){
	    		e.printStackTrace();
	    		 ajaxJson.setSuccess(false).setStatus(250).setData(null);
	    	}
	    	return ajaxJson;
	    }
}
